package m1.server.config.component;

import m1.server.config.component.componentInterface.SecurityManagerInterfaceProvided;
import m1.server.config.component.componentInterface.SecurityManagerInterfaceRequired;
import m1.server.config.component.port.CredentialQuery;
import m1.server.config.component.port.CredentialQuerySend;
import m1.server.config.component.port.SecurityAuthorization;
import m1.server.config.component.port.SecurityAuthorizationSend;
import m2.component.Component;
import m2.links.InternalBinding;

public class SecurityManager extends Component{
	
	private static SecurityManager securityManager = null;
	
	/**
	 * 
	 */
	private SecurityManager(){		
		SecurityManagerInterfaceProvided securityManagerInterfaceProvided = new SecurityManagerInterfaceProvided();
		SecurityManagerInterfaceRequired securityManagerInterfaceRequired = new SecurityManagerInterfaceRequired();
		addComponentInterfaceProvided(securityManagerInterfaceProvided);
		addComponentInterfaceRequired(securityManagerInterfaceRequired);
		addProvidedPort(new CredentialQuery("CredentialQuery"), new SecurityAuthorizationSend("SecurityAuthorizationSend"));
		addRequiredPort(new CredentialQuerySend("CredentialQuerySend"), new SecurityAuthorization("SecurityAuthorization"));
		securityManagerInterfaceProvided.buildService();
		securityManagerInterfaceRequired.buildService();
		
		InternalBinding internalBindingIn = new InternalBinding();
		internalBindingIn.internalBindingIn( getProvidedPort("SecurityAuthorizationSend"), null, null, getRequiredPort("CredentialQuerySend"));
		
		InternalBinding internalBindingOut = new InternalBinding();
		internalBindingOut.internalBindingOut( getRequiredPort("SecurityAuthorization"), null, null, getProvidedPort("CredentialQuery"));
		
	}
	
	/**
	 * 
	 * @return
	 */
	public static SecurityManager getInstance(){
		if (securityManager == null){
			securityManager = new SecurityManager();
		}
		return securityManager;
	}
	
}
